﻿/*
you have to import the class into whatever class you want to use it in
import com.utils.Transition
then create an instance of it:
public var myTransition:Object;
mcs_arr = new Array("diagram_mc", "intro_mc")
myTransition = new Transition(mcs_arr, root_obj);
so
it requires 2 things
an array of any mcs that you want to use it with
I actually put in all the mcs from the fla because it stores their coords and then makes them invisible and I like the control this gives me
I can then bring things in and out when I want to
the 2nd thing you pass into it is scope
once I pass these two things in I run these two methods to store and then hide the mcs
myTransition.storeLocations();
myTransition.hideMcs();
then to actually move an mc in you would use a line like this
myTransition.transClip(root_obj.intro_mc, "in", "left", null, null);
the nulls are to do with callbacks. The first is the scope and the second the method. The method can either be a reference to a method or an inline function
so for example
myTransition.transClip(step_obj.clip_mc.diagram_mc, "in", "right", this, function () {
myTransition.transClip(step_obj.clip_mc.intro_mc, "in", "left", null, null);
});

if you go into VSS
and go to Caltrans/Savvy/proto1
download that whole folder
here's an example of me using myTransiotion on a savvy

*/
import mx.utils.Delegate;
class com.utils.Transition extends MovieClip {
	public var mcs_arr:Array;
	public var root_obj:MovieClip;
	public var callBackScope:Object;
	public var params_arr:Array;
	public var p_params_arr:Array;
	public var callBack:Function;
	public var ignore_str:String;
	public function Transition(p_mcs_arr:Array, p_root_obj:MovieClip) {
		trace(newline+"Transition(p_mcs_arr.length: "+p_mcs_arr.length+")");
		this.mcs_arr = p_mcs_arr;
		this.root_obj = p_root_obj;
		trace("this.root_obj: "+this.root_obj);
	}
	public function storeLocations():Void {
		for (var i:Number = 0; this.mcs_arr[i] != undefined; i++) {
			this.root_obj[this.mcs_arr[i]].origX_num = this.root_obj[this.mcs_arr[i]]._x;
			this.root_obj[this.mcs_arr[i]].origY_num = this.root_obj[this.mcs_arr[i]]._y;
		}
	}
	public function hideMcs(p_ignore_str:String):Void {
		this.ignore_str = p_ignore_str;
		for (var i:Number = 0; this.mcs_arr[i] != undefined; i++) {
			//trace("this.root_obj: "+this.root_obj);
			//trace("this.mcs_arr[i]: "+this.mcs_arr[i]);
			//trace("this.root_obj[this.mcs_arr[i]]: "+this.root_obj[this.mcs_arr[i]]+" ignore_str: "+ignore_str);
			if (this.mcs_arr[i] != ignore_str) {
				this.root_obj[this.mcs_arr[i]]._visible = false;
			}
		}
	}
	public function transClip(my_mc:MovieClip, transType:String, transDir:String, callBackScope:MovieClip, callBack:Function, p_params_arr:Array):Void {
		//trace(newline+"transClip("+my_mc+", "+transType+", "+transDir+", "+callBackScope+", "+callBack+", "+p_params_arr+");");
		this.callBackScope = callBackScope;
		this.callBack = callBack;
		this.params_arr = new Array();
		this.params_arr = p_params_arr.slice();
		my_mc.callBack = callBack;
		my_mc.callBackScope = callBackScope;
		my_mc.params_arr = new Array();
		//for (var i:Number = 0; this.params_arr[i] != undefined; i++) {
			//my_mc.params_arr[i] = this.params_arr[i];
		//}
		my_mc.params_arr = this.params_arr.slice();
		if (my_mc.params_arr != undefined) {
			//trace("this.params_arr.length: "+this.params_arr.length);
			//trace("my_mc.params_arr: "+my_mc.params_arr+" typeof: "+typeof my_mc.params_arr);
		}
		if (transType == "in") {
			switch (transDir) {
			case "top" :
				my_mc._y = -1500;
				my_mc._visible = true;
				break;
			case "bottom" :
				my_mc._y = 1500;
				my_mc._visible = true;
				break;
			case "right" :
				my_mc._x = 1100;
				my_mc._visible = true;
				break;
			case "left" :
				my_mc._x = -1100;
				my_mc._visible = true;
				break;
			}
			my_mc.tween(["_x", "_y"], [my_mc.origX_num, my_mc.origY_num], 1, "easeOutQuad", 0, function () {
				this.callBack.apply(this.callBackScope, [this.params_arr]);
				if (this.params_arr != undefined) {
					//trace(newline+"my_mc: "+this+" this.params_arr: "+this.params_arr);
				}
			});
		} else if (transType == "out") {
			switch (transDir) {
			case "top" :
				my_mc.tween(["_x", "_y"], [my_mc.origX_num, -1500], 1, "easeInQuad", 0, function () {
					this.callBack.apply(this.callBackScope, [this.params_arr]);
					this._visible = false;
				});
				break;
			case "bottom" :
				my_mc.tween(["_x", "_y"], [my_mc.origX_num, 1500], 1, "easeInQuad", 0, function () {
					this.callBack.apply(this.callBackScope, [this.params_arr]);
					this._visible = false;
				});
				break;
			case "right" :
				my_mc.tween(["_x", "_y"], [1500, my_mc.origY_num], 1, "easeInQuad", 0, function () {
					this.callBack.apply(this.callBackScope, [this.params_arr]);
					this._visible = false;
				});
				break;
			case "left" :
				my_mc.tween(["_x", "_y"], [-1500, my_mc.origY_num], 1, "easeInQuad", 0, function () {
					this.callBack.apply(this.callBackScope, [this.params_arr]);
					this._visible = false;
				});
				break;
			}
		}
	}
}
